<!doctype html>
<html>
{include file="head.html"}

<body>
<div class="fullscreen">
        <div class="scroll_content">
            <div class="topfixed">
                <div class="t_left"><a href="/index.php?m=sushe&a=my"><i class="back"></i></a></div>
                <div class="t_main">添加室友</div>
            </div>
            <div class="paddingheight"></div>

        </div>
    </div>
    <div class="chooseSchool_search" style="margin-bottom: 10px;">
        <input type="text" id="keyword" placeholder="请输入姓名/手机" class="inp">
        <button type="button" class="btn" id="search"></button>
    </div>
    <ul class="my_roommate_list add" id="search-list">
         

    </ul>
    <input id="invite-userid" type="hidden" value="0">
    <button class="cart_change_btn" id="send_invite" style="display:none">发送邀请</button>
    <script id="search-list-tpl" type="text/html">
	<%for(var i=0;i<data.length;i++){%>
    	 <li class="clearfix"  v="<%=data[i].userid%>">
            <div class="avatarbox">
                <img src="<%=data[i].user_head%>.100x100.jpg" onerror="err_user_head(this)" class="img"><br>

            </div>
            <div class="infobox">
                <p class="name">
                    <span class="fl"><%=data[i].nickname%></span>
                </p>

                <p class="n_info"><%=data[i].info%></p>

            </div>
            <span class="select"></span>
        </li>
	<%}%>	
    </script>
    <script src="/plugin/jquery/template-native.js"></script>
    <script>
        $(document).on("click",".my_roommate_list.add li",function (e) {
            if($(this).hasClass("cur")){
                $(this).removeClass("cur");
				$("#invite-userid").val(0);
            }else{
				$("#invite-userid").val($(this).attr("v"));
            	$(this).addClass("cur").siblings().removeClass("cur");
            }
        });
		
		$(function(){
			$("#search").on("click",function(){
				var keyword=$("#keyword").val();
				if(keyword.length>1){
					$.get("/index.php?m=sushe&a=invite_search&ajax=1",{keyword:keyword},function(data){
						if(data.error){
							 $("#send_invite").hide();
							
							$("#search-list").html();
							$("#invite-userid").val(0);
							skyToast(data.message);
						}else{
							var html=template("search-list-tpl",data);
							 $("#search-list").html(html);
							 $("#invite-userid").val(0);
							 $("#send_invite").show();
						}
					},"json");
				}else{
					skyToast('搜索内容不能少于2个字');
				}
			});
			
			$("#send_invite").on("click",function(){
				var userid=$("#invite-userid").val();
				$.get("/index.php?m=sushe&a=invite_save&ajax=1",{userid:userid},function(data){
					if(data.error){
						skyToast(data.message);
					}else{
						skyToast('邀请成功');
					}
				},"json");
			});
		});
    </script>

</body>
</html>
